<!--父级页面:所有页面(除登录页)共有的左侧与顶部条-->
<template>
  <div class="page-container">
    <el-header class="fixed-header">
      <el-menu>
        <!-- 顶部条的菜单栏  -->
        <el-row style="padding-top:10px;">
          <el-col :span="2"></el-col>
          <el-col :span="1" style="display: flex; justify-content: center;padding-bottom: 15px;">
            <!-- <el-avatar>是把图片裁成圆的 -->
            <el-avatar src="/imgs/home/logo.png" style="width: 35px; height: 35px;"></el-avatar>
          </el-col>
          <el-col :span="2" style="color: #000; justify-content: center; font-weight: bold; text-align: center; display: flex; align-items: center;padding-bottom: 15px;">
            <span style="text-align: center">招财蛙</span>
          </el-col>
          <el-col :span="6" style="display: flex; justify-content: center;">
            <!--              <a :href="resume">我的简历</a>-->
            <a :href="candidateRecords" class="menu-link">我的招聘</a>
            <a :href="interestedJobs" class="menu-link">感兴趣岗位</a>
          </el-col>


          <el-col :span="6" padding-right="100px" style="color: #000; justify-content: center; font-weight: bold; text-align: center; display: flex; align-items: center;padding-bottom: 15px;">
            <el-dropdown trigger="click" style="position:absolute;right:20px;">
              <span style="font-size:19px;font-weight:bold;">
                {{user.username}}
                <el-icon><arrow-down/></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>


        </el-row>
      </el-menu>
    </el-header>
    <!--可滚动区域      -->
    <div class="scroll-container">
    <el-main style="padding: 20px;">
      <el-row>
        <img src="/imgs/home/picture.png" style="width: 1456px; height: 310px;">
      </el-row>
<!--      <el-card  v-for="(job, index) in jobs"
                :key="job.id"
                style="width: 793px;height: 220px;margin-left:183px;margin-top: 20px;">
        <el-descriptions :title="job.jobName" :data="job">
          <el-descriptions-item label="城市id" >{{job.cityId}}</el-descriptions-item>
          <el-descriptions-item label="公司id">{{job.companyId}}</el-descriptions-item>
          <el-descriptions-item label="要求">{{job.requirements}}</el-descriptions-item>
          <el-descriptions-item label="薪资范围" >{{job.salaryRange}}</el-descriptions-item>
          <el-descriptions-item label="地址">{{job.location}}</el-descriptions-item>
          <el-descriptions-item label="状态">{{job.status}}</el-descriptions-item>
        </el-descriptions>
        <hr style="border-color: #ccc; border-width: 1px 0 0 0;">
        <el-row>
          <el-descriptions>
            <el-descriptions-item label="发布日期" >{{job.postTime}}</el-descriptions-item>
          </el-descriptions>
          <el-button type="primary" plain style="margin-left: 400px;" @click="cancelFollow(job.id)">取消关注</el-button>
          <el-button type="primary" style="margin-left: 20px;">投一个呗</el-button>
        </el-row>
      </el-card>-->


      <div class="job-card" v-for="(job,index) in jobs" :key="job.id">
        <!-- 左侧职位信息区域 -->
        <div class="job-info">
          <h3 class="job-title">{{ job.title }}</h3>
          <p class="salary_range">{{ job.salaryRange }}</p>
          <p class="experience">
            {{ job.experience }} / {{ job.education }}
          </p>
          <ul class="welfare-list">
            <li v-for="(welfare, index) in job.welfareList" :key="index">
              {{ welfare }}
            </li>
          </ul>
          <div class="publish-info">
            <span class="publish-label">发布日期</span>
            <span class="postTime">{{  job.postTime ? new Date(job.postTime).toLocaleDateString() : '' }}</span>
          </div>
        </div>
        <!-- 右侧公司及联系人信息区域 -->
        <div class="company-info">
          <img :src="job.companyLogo" alt="公司logo" class="company-logo" />
          <div class="company-detail">
            <h4 class="company-name">{{ job.companyName }}</h4>
            <p class="industry">{{ job.industry }}</p>
            <div class="contact-info">
              <img :src="job.contactAvatar" alt="联系人头像" class="contact-avatar" />
              <span class="contact-name">{{ job.contactName }}</span>
              <span class="contact-phone">{{ job.contactPhone }}</span>
            </div>
          </div>
<!--          <button class="apply-button">{{ job.applyButtonText }}</button>-->
<!--          <el-row>
            <el-button type="primary" plain style="margin-left: 400px;" @click="cancelFollow(job.id)">取消关注</el-button>
            <el-button type="primary" style="margin-left: 20px;">投一个呗</el-button>
          </el-row>-->
              <button   style= "margin-left: 150px;width: 85px; height: 35px;border: none;border-radius: 4px;" @click="cancelFollow(job.id)">取消关注</button>
              <button class="apply-button">投一个呗</button>
        </div>
      </div>
    </el-main>
    <el-footer class="custom-footer" style="background: #f5f7fa" padding="20px">
        <el-row :gutter="20">
          <!-- 用户帮助区块 -->
          <el-col :xs="24" :sm="8" :md="8" class="footer-section">
            <div class="footer-title">用户帮助</div>
            <ul class="help-list">
              <!-- 使用数据驱动方式渲染帮助链接 -->
              <li v-for="(item, index) in helpLinks" :key="index">
                <el-link :href="item.url" type="info">{{ item.title }}</el-link>
              </li>
            </ul>
          </el-col>

          <!-- 联系方式区块 -->
          <el-col :xs="24" :sm="8" :md="8" class="footer-section">
            <div class="footer-title">联系我们</div>
            <div class="contact-info">
              <p>📞 客服电话：{{ contactInfo.phone }}</p>
              <p>📧 企业邮箱：
                <el-link :href="`mailto:${contactInfo.email}`" type="info">
                  {{ contactInfo.email }}
                </el-link>
              </p>
              <p>📍 公司地址：{{ contactInfo.address }}</p>
            </div>
          </el-col>

          <!-- 二维码区块 -->
          <el-col :xs="24" :sm="8" :md="8" class="footer-section qr-codes">
            <div class="footer-title">关注我们</div>
            <el-row :gutter="10">
              <el-col
                  v-for="(qr, index) in qrCodes"
                  :key="index"
                  :span="12"
                  class="qr-item"
              >
                <img :src="qr.image" :alt="qr.title" class="qr-image">
                <p class="qr-desc">{{ qr.title }}</p>
              </el-col>
            </el-row>
          </el-col>
        </el-row>

        <!-- 版权信息 -->
        <div class="copyright">
          <hr class="footer-divider">
          <p>© 2023 Your Company. All rights reserved. | 备案号：京ICP备12345678号</p>
        </div>
      </el-footer>

    </div>
  </div>
</template>

<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";

// const resume=ref('http://localhost:9090/resume')
const candidateRecords=ref('http://localhost:9090/candidateRecords')
const interestedJobs=ref('http://localhost:9090/interestedJobs')
// 定义岗位信息数组
/*const jobs = ref([
  { id:1,title: '前端开发工程师', salary: '6k-13k',experience: '经验3-5年/学历不限',company:'京东数科',welfare:'年终奖',hr:'马克',contact:'16666666666',date:'2025-05-05'},
  { id:2,title: '后端开发工程师', salary: '7k-13k',experience: '经验3-5年/学历不限',company:'京东数科',welfare:'年终奖',hr:'马克',contact:'16666666666',date:'2025-05-05'},
  { id:3,title: '全栈开发工程师', salary: '8k-13k',experience: '经验3-5年/学历不限',company:'京东数科',welfare:'年终奖',hr:'马克',contact:'16666666666',date:'2025-05-05'}
]);*/
// 定义数组用来保存岗位数据
const jobs = ref([]);

//获取当前登录的用户信息
const user = ref(getUser());
// 定义加载岗位列表的方法
const loadJobs = ()=>{
  let userId = user.value.id;
  axios.get(BASE_URL+'/interestedJobs/select/'+userId)
      .then(response => {
        if(response.data.state===200){
          // / 拿到原始数据后，遍历补充属性
          const processedJobs = response.data.data.map(job => ({
            ...job, // 保留原有字段
            applyButtonText: '应聘记录', // 补充静态值
            companyLogo: '/imgs/companyLogo.png',
            contactAvatar: '/imgs/contactAvatar.png'
          }));
          jobs.value = processedJobs; // 替换为处理后的数组
          // jobs.value = response.data.data;
        }else{
          ElMessage.error(response.data.message);
        }
      })
}
// 一进入页面就立即加载岗位列表
onMounted(() => {
  loadJobs();
})
// 数据部分
const helpLinks = ref([
  { title: '常见问题', url: '/faq' },
  { title: '用户协议', url: '/terms' },
  { title: '隐私政策', url: '/privacy' },
  { title: '售后服务', url: '/support' }
])
const contactInfo = ref(
  {phone: '400-123-4567',
    email: 'support@yourcompany.com',
    address: '北京市朝阳区科技大厦12层'}
);
const qrCodes = ref([      {
  title: '微信公众号',
  image: new URL('@/assets/qr-wechat.png', import.meta.url).href
  // image: require('@/assets/qr-wechat.png')
},
  {
    title: '小程序码',
    image: new URL('@/assets/qr-miniprogram.png', import.meta.url).href
    // image: require('@/assets/qr-miniprogram.png')
  }
  ])
// 加载退出登录的方法
const logout = ()=>{
  if(confirm('您确认要退出登录吗?')){
    //清空登录时存入的当前用户的信息
    localStorage.removeItem('user');
    //退出后返回到登录页
    window.location.href = '/login';
    //也需要将刚刚取出来的user对象清空
    user.value = '';
  }
}
// 定义取消关注的方法
const cancelFollow = (jobId)=>{
  if(confirm('您确认要取消关注该岗位吗?')){
    axios.post(BASE_URL+'/interestedJobs/delete/'+jobId)
        .then(response => {
          if(response.data.state===200){
            //取消关注成功后，重新加载岗位列表
            ElMessage.success('取消关注成功');
            loadJobs();
          }else{
            ElMessage.error(response.data.message);
         }
        })
  }
}
</script>
<style scoped>
.menu-link {
  color:  #000;
  font-weight: bold;
  margin-right: 10px;
  text-decoration: none;
  padding-top: 8px;
  padding-left:60px;
}
/* 关键样式 */
.page-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.fixed-header {
  position: fixed !important; /* 固定定位 */
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000; /* 确保在最上层 */
  background: white; /* 添加背景色避免透明 */
  box-shadow: 0 2px 12px rgba(0,0,0,0.1); /* 可选：添加阴影增强层次感 */
}

.scroll-container {
  flex: 1;
  overflow-y: auto;
  margin-top: 60px; /* 需要等于 header 高度 */
}

/* 样式部分 */
.custom-footer {
  position: static !important; /* 关闭固定定位 */
  background-color: #f8f9fa;
  padding: 40px 20px;
  color: #666;
}

.footer-section {
  margin-bottom: 30px;
  padding: 0 20px;
}

.footer-title {
  font-size: 16px;
  color: #333;
  margin-bottom: 15px;
  font-weight: bold;
  padding-left: 10px;
  border-left: 4px solid #409EFF; /* 左侧装饰线 */
}

.help-list {
  list-style: none;
  padding-left: 0;
}

.help-list li {
  margin-bottom: 10px;
}

.contact-info p {
  margin: 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.qr-codes {
  text-align: center;
}

.qr-image {
  width: 120px;
  height: 120px;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 5px;
  background: white;
}

.qr-desc {
  margin-top: 8px;
  font-size: 12px;
  color: #999;
}

.copyright {
  text-align: center;
  margin-top: 40px;
  font-size: 12px;
  color: #999;
}

.footer-divider {
  border: 0;
  border-top: 1px solid #e4e7ed;
  margin: 20px 0;
}



.job-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px;
  border: 1px solid #eee;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  width: 50%;
  margin: 0 auto;
  margin-top: 20px;
}
.job-info {
  flex: 1 1 50%; /* 修改为固定占据50%宽度，同时允许收缩 */
  padding-top: 10px;
  padding-right: 8px; /* 调整内边距代替原来的margin-right */
  padding-left: 20px;
}
/*.company-info {
  flex: 1 1 50%; !* 修改为固定占据50%宽度，同时允许收缩 *!
  padding-left: 8px; !* 添加左侧内边距，保持两侧平衡 *!
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}*/
.company-info {
  padding-top: 10px;
  flex: 1 1 50%;
  padding-left: 8px;
  display: flex;
  /* 改为水平排列，子元素同一行显示 */
  flex-direction: row;
  /* 垂直方向居中对齐，可根据需求调整 */
  align-items: center;
  /* 若子元素超出宽度，可设置换行，根据需求决定是否添加 */
  flex-wrap: wrap;
}
.job-title {
  font-size: 18px;
  font-weight: bold;
  margin: 0 0 8px 0;
  text-align: left; /* 文本内容居中 */
}
.salary_range {
  color: #ff9900;
  font-size: 16px;
  margin: 0 0 4px 0;
  text-align: left; /* 文本内容靠左 */
}
.experience {
  color: #999;
  margin: 0 0 8px 0;
  text-align: left; /* 文本内容居中 */
}
.welfare-list {
  list-style: none;
  padding: 0;
  margin: 0 0 8px 0;
  display: flex;
  gap: 8px;
}
.welfare-list li {
  background-color: #f5f5f5;
  padding: 4px 8px;
  border-radius: 4px;
  color: #666;
}
.publish-info {
  display: flex;
  align-items: center;
  color: #999;
}
.postTime{
  background-color: #f5f5f5;
  padding: 4px 8px ;
  border-radius: 4px;
  margin-right: 8px;
  margin-left: 4px;
}
/*.company-logo {
  width: 120px;
  height: 120px;
  border-radius: 4px;
  margin-bottom: 8px;
}*/
.company-logo {
  width: 120px;
  height: 120px;
  border-radius: 4px;
  /* 让 logo 占容器宽度的 30% */
  flex: 0 0 30%;
  /* 去掉底部 margin，因为现在是水平排列 */
  margin-bottom: 0;
  /* 可根据需求设置右侧 margin，隔开与其他内容的距离 */
  margin-right: 10px;
}
.company-detail {
  /* 占剩余空间的 70% */
  flex: 1;
  display: flex;
  flex-direction: column;
  /* 若需要垂直居中，可加这个，根据需求调整 */
  /* justify-content: center; */
}
.company-name {
  font-size: 16px;
  font-weight: bold;
  margin: 0 0 4px 0;
  text-align: left; /* 文本内容靠左 */
}
.industry {
  text-align: left; /* 文本内容靠左 */
  color: #999;
  margin: 0 0 8px 0;
}
.contact-info {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}
.contact-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 8px;
}
.contact-name {
  margin-right: 8px;
}
.contact-phone {
  color: #999;
}
.apply-button {
  margin-left: auto; /* 将按钮推到右侧 */
  /* 保持原有样式 */
  background-color: #007bff;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}
.apply-button:hover {
  background-color: #0056b3;
}
</style>

